package com.mabs.util;

import java.util.List;

import com.mabs.entity.Person;

public class CheckUtil {
	/** QQ号码的正则表达式*/
	private static final String q = "[1-9][0-9]{4,14}";
	/** 电话号码的正则表达式*/
	private static final String tel = "1[3|5|7|8|]\\d{9}";
	static String ph = null;
	static String q1 = null;
	static String gen = null;

	public static String checkPhone(String phone, List<Person> persons) {
		ph = phone;
		for (Person p : persons) {
			if (p.getPhone().equals(ph)) {
				System.out.println("手机号重复,请您重新输入...");
				ph = InputUtil.getInput("请输入新手机号码:");
				checkPhone(ph, persons);
			}
		}
		if (!ph.matches(tel)) {
			System.out.println("手机号错误,请您重新输入...");
			ph = InputUtil.getInput("请输入新手机号码:");
			checkPhone(ph, persons);
		}
		return ph;
	}

	public static String checkQq(String qq, List<Person> persons) {
		q1 = qq;
		for (Person p : persons) {
			if (p.getQq().equals(q1)) {
				System.out.println("qq号重复,请您重新输入...");
				q1 = InputUtil.getInput("请输入新qq号码:");
				checkQq(q1, persons);
			}
		}
		if (!q1.matches(q)) {
			System.out.println("qq号错误,请您重新输入...");
			q1 = InputUtil.getInput("请输入新qq号码:");
			checkQq(q1, persons);
		}
		return q1;
	}

	public static String checkGender(String gender) {
		gen = gender;
		if (!gender.equals("男") && !gender.equals("女")) {
			System.out.println("性别错误,请您重新输入...");
			gen = InputUtil.getInput("请重新输入性别:");
			checkGender(gen);
		}
		return gen;
	}
}
